Page({
    data: {
      notices: [
        {title:"公告标题1"},
       {title:"公告标题2"}, 
        {title:"公告标题3"},
        {title:"公告标题4"},
        {title:"公告标题5"},
        {title:"公告标题6"}

      
      ],
      currentNoticeIndex: 0,
      activeTab: 0
    },
  
    onLoad() {
      this.startNoticeRoll();
    },
  
    onUnload() {
      if (this.noticeTimer) {
        clearInterval(this.noticeTimer);
      }
    },
  
    startNoticeRoll() {
      this.noticeTimer = setInterval(() => {
        const { currentNoticeIndex, notices } = this.data;
        let newIndex = currentNoticeIndex + 1;
        
        if (newIndex >= notices.length) {
          newIndex = 0;
        }
        
        this.setData({
          currentNoticeIndex: newIndex
        });
      }, 3000);
    },
  
    /**
     * 修复后的标签切换方法
     * 确保正确获取标签索引
     */
    switchTab(e) {
      // 修复：明确获取data-index属性的值并转为数字类型
      const index = Number(e.currentTarget.dataset.index);
      this.setData({
        activeTab: index
      });
      
      // 可以在这里添加标签切换后的逻辑
      if (index === 0) {
        console.log("切换到丢失标签");
      } else {
        console.log("切换到捡到标签");
      }
    },
  
    goHome() {
      wx.switchTab({
        url: '/pages/shouye'
      });
    },
  
    goSquare() {
      wx.navigateTo({
        url: '/pages/guangchang'
      });
    },
  
    goPublish() {
      wx.navigateTo({
        url: '/pages/shiwuxinxifabu'
      });
    },
  
    goMessage() {
      wx.navigateTo({
        url: '/pages/xiaoxi'
      });
    },
  
    goMine() {
      wx.switchTab({
        url: '/pages/wode'
      });
    },
  
    goSearch() {
      wx.navigateTo({
        url: '/pages/search/search'
      });
    }
  });
  